package com.sheng.project;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author liusheng
 * @date 2022/09/06
 */
@Slf4j
@SpringBootApplication
@EnableJpaAuditing// 启动 JPA 的审计功能，使 @CreatedDate 和 @LastModifiedDate 等功能生效
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com\\.sheng\\.project\\.study\\..*")})
@EnableFeignClients
public class Application {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(Application.class);
        Environment environment = context.getEnvironment();
        String store = StrUtil.isNotBlank(environment.getProperty("server.ssl.key-store")) ? "https" : "http";
        log.info("\n--------------------------------------------------------------\n\t" +
                        "Application: {} is running! Access URLs:\n\t" +
                        "Local:       {}://localhost:{}\n\t" +
                        "External:    {}://{}:{}\n\t" +
                        "Profile(s):  {}\n" +
                        "--------------------------------------------------------------",
                environment.getProperty("spring.application.name"),
                store,
                environment.getProperty("server.port"),
                store,
//                IpUtil.getAllIntet4Addresses().get(1),
                InetAddress.getLocalHost().getHostAddress(),
                environment.getProperty("server.port"),
                environment.getActiveProfiles()
        );
    }
}
